package com.heima.mapper;

import com.github.pagehelper.Page;
import com.heima.pojo.VendingMachine;
import com.heima.pojo.dto.VmPageDto;
import com.heima.pojo.vo.VendingMachineVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface VmMapper {
    /**
     * 分页查询设备
     */
    Page<VendingMachineVo> pageQuery(VmPageDto dto);

    /**
     * 新增设备
     * @param vendingMachine
     */
    @Insert("insert into tb_vending_machine(create_user_id,node_id,vm_type,create_time,update_time,inner_code)" +
            " values(#{createUserId},#{nodeId},#{vmType},#{createTime},#{updateTime},#{innerCode})")
    void addVm(VendingMachine vendingMachine);

    /**
     * 修改设备点位
     * @param vendingMachine
     */
    @Update("update tb_vending_machine set node_id = #{nodeId} where id = #{id}")
    void updateNodeId(VendingMachine vendingMachine);

    /**
     * 根据设备编号拿到regionId
     * @param innerCode
     * @return
     */
    @Select("select * from tb_vending_machine where inner_code = #{innerCode}")
    VendingMachine queryByInnerCode(String innerCode);
}
